Skip to content

Improve Windows Build Reliability with Smarter Npcap SDK Resolution#1

Open
manucian-official wants to merge 1 commit intoomerarslan0:mainfrom
manucian-official:patch-1
Open

Improve Windows Build Reliability with Smarter Npcap SDK Resolution#1
manucian-official wants to merge 1 commit intoomerarslan0:mainfrom
manucian-official:patch-1

Conversation

@manucian-official
Copy link
Copy Markdown

🚀 Improve Windows Npcap SDK Detection in build.rs

🧠 Overview

This update refactors the emit_windows_packet_sdk_links logic to make Npcap SDK detection more robust, maintainable, and cross-architecture compatible.


⚡ Key Improvements

🔥 1. Smarter SDK Discovery

  • Supports multiple detection strategies:
    • NPCAP_SDK_DIR environment variable (highest priority)
    • Workspace-relative paths (../npcap-sdk/Lib)
    • Common installation directories
    • ProgramFiles / ProgramFiles(x86) auto-detection
  • Eliminates duplicate path checks using HashSet

⚙️ 2. Architecture-Aware Linking

  • Automatically detects target architecture (x86, x86_64)
  • Dynamically searches in appropriate subdirectories (x64, x86)
  • Removes hardcoded assumptions

💎 3. Cleaner & Modular Code

  • Extracted helper functions:
    • has_required_libs() → validates SDK presence
    • arch_subdir() → resolves architecture-specific paths
  • Improved readability and maintainability

🧪 4. Better Build Diagnostics

  • Clear cargo:warning messages when:
    • SDK is found
    • SDK is missing
  • Easier debugging in CI/CD environments

🚀 5. Safer Platform Handling

  • Uses cfg!(target_os = "windows") instead of runtime env checks
  • Ensures logic only runs on Windows targets

📦 Behavior

  • Links against:
    • Packet.lib
    • wpcap.lib
  • Emits correct cargo:rustc-link-search automatically
  • Gracefully warns if SDK is not found (non-breaking)

💡 Why This Matters

  • Improves developer experience (zero-config in most cases)
  • Reduces CI failures due to missing SDK paths
  • Ensures compatibility across different Windows setups
  • Makes the build script production-ready

🔧 Optional Follow-ups

  • Add Linux/macOS libpcap auto-detection
  • Cache detected SDK path for faster builds
  • Add strict mode to fail build if SDK is required

@manucian-official manucian-official changed the title Update build.rs Improve Windows Build Reliability with Smarter Npcap SDK Resolution Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant